<?php
namespace app\common\Service;
use app\common\model\Questions;
use app\common\model\QuestionDb;
use app\common\model\Qbank;
use app\common\model\Paper;
use app\common\logic\DrawQuestion;
use think\Model;
use think\Db;

/* 试卷抽题相关的业务类 */
class QuesPaper extends Model
{
	
	
	/* 所有错误提示信息 */
	public $error ='';
	public $ob_ques_model;
	public $ob_qbank_model;
	public $ob_paper_model;
	

	public function __construct(){
		$this->ob_ques_model =  new Questions();
		$this->ob_qbank_model =  new Qbank();
		$this->ob_quesdb_model =  new QuestionDb();
		$this->ob_paper_model =  new Paper();
	}
	
	public function getError()
	{
		return $this->error;		
	}
	
	public function setError($str){
		$this->error = $str;
	}
	
	
	/*
	*@func	getQuestionsByPaperId 根据试卷ID抽题
	*@param	$id 试卷ID
	*@result 返回数组
	*$staus 是否二次处理
	*/	
	public function getQuestionsByPaperId($id,$style=1,$staus=0){
		
		if(empty($id)) 
		{
			$this->error = 'ID不存在，非法操作';	
			return false;
		}
		$paper_conf = $this->ob_paper_model->getInfo($id);

		$ob_dw = new DrawQuestion();

		//如果为随机抽题
		switch($paper_conf['p_papertype']){
			case 1:
				$questions = $ob_dw->randomDrawQues($paper_conf['p_dbs'],$paper_conf['ratio'],$style);
				break;					
			case 2: //固定抽题				
				$questions = unserialize($paper_conf['p_data']);				
				break;				
			default:			
					break;		
		}
		if($staus){
			$arr =array();
			foreach($questions as $v){
				foreach($v as $val){
					$arr[] = $val;
				}
			}
			$questions = $arr;
		}
		return $questions;		
	}		
	
	
	
}
	